<?php
/**
 * (commands) Amazon订单
 */
namespace App\Console\Commands\SpApi\Order;

use App\Logic\Amazon\Api\OrderWork;
use App\Models\Amazon\AmazonOrder;
use App\Models\Basics\AmazonAccount;
use Illuminate\Console\Command;
class GetOrdersByOrderIds extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sp-order:get-orders-order {orderId*} {--areaId=null}';

    /**
     * The console command description.
     * @var string
     */
    protected $description = 'exe func';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $orderId = $this->argument('orderId');
        if(!$orderId){
            $this->error('请提供订单号!');
        }else{
            $_orders = array_slice($orderId,0,10);
            $hasId = AmazonOrder::query()->whereIn('amazon_order_id',$_orders)
                ->pluck('amazon_order_id')
                ->toArray();
            $need = array_values(array_unique(array_diff($_orders,$hasId)));
            if($need){
                if($areaId = $this->option('areaId')){
                    $accounts = AmazonAccount::optionsForApi(['area_id' => $areaId]);
                }else{
                    $accounts = AmazonAccount::optionsForApi();
                }
                OrderWork::getOrdersViaOrderIDs($accounts,$need);
            }
            $this->info('订单同步完成！');
        }
    }
}
